﻿using UnityEngine;
using System.Collections;
using TileMapClasses;
using GeneralStorageClasses;
using PlayerClasses;

namespace GUIElements
{
	public class missionPane : MonoBehaviour
	{
		public Rect paneRect;
		public GUIStyle paneStyle;
		private bool displayTile;
		private int displayID;

		// Use this for initialization
		void Start ()
		{
			float width = paneStyle.active.background.width;
			float height = paneStyle.active.background.height;
		
			paneRect = new Rect (0, 100, width, height);
			displayTile = false;
			displayID = -1;
			Tile.tileSelected += selectorListener;
		}

		void OnDestroy ()
		{
			Tile.tileSelected -= selectorListener;
		}
		void OnGUI ()
		{
			GUI.Window (20, paneRect, windowContents, "", paneStyle);
		}

		private void selectorListener (bool state, int TileID)
		{
			displayTile = state;
			displayID = TileID;
		}
	
		private void windowContents (int windowID)
		{
			/*TODO:
		 * Label for title
		 * BOX for image
		 * lable for tile info
		 * lable for objectives
		 * lable for rewards
		 * button for move, button for attack
		 */

			if (displayTile == true) {
				Story tempStory = tileManager.Instance [displayID].storyObj;
				GUI.Label (new Rect (10, 10, 100, 20), tempStory.Title);
				GUI.Box (new Rect (10, 40, 100, 100), "image");
				GUI.Label (new Rect (10, 160, 100, 20), tempStory.Info);
				GUI.Label (new Rect (10, 240, 200, 20), tempStory.Objectives);
				GUI.Label (new Rect (10, 320, 100, 20), "Rewards");


			} else {
				GUI.Label (new Rect (10, 10, 100, 20), "?????");
				GUI.Box (new Rect (10, 40, 100, 100), "?????");
				GUI.Label (new Rect (10, 160, 100, 20), "?????");
				GUI.Label (new Rect (10, 240, 200, 20), "?????");
				GUI.Label (new Rect (10, 320, 100, 20), "?????");
			}

			if (GUI.Button (new Rect (5, 400, 70, 20), "Move")) {
				if (displayTile == true) {
					if (tileManager.Instance [displayID].Controlled == 1) {
						Vector3 newPos = tileManager.Instance [displayID].potatas.transform.position;
						newPos.y += .2f;
						tent.Instance.pitchTent (new Vector3 (newPos.x, newPos.y, newPos.z));
					}
				}
			}
			if (GUI.Button (new Rect (80, 400, 70, 20), "Attack")) {
				if (displayTile == true) {

					Debug.Log ("Loading Battlefield");
					Squad.Instance.SquadSave (0); //saving as a transfer
					if (tileManager.Instance [displayID].Controlled != 1) {
						tileManager.Instance [displayID].Controlled = 1;
					}
					Application.LoadLevel ("battlefield");
				}
			}
		}
	}
}
